package com.zto.sch.dao;

import com.zto.sch.invoke.MyInvocationHandler2;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.lang.reflect.Proxy;

/**
 * @program: javatest
 * @description:
 * @author: sch
 * @create: 2020-09-20 21:43
 **/
public class UserDaoImpl2 implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        try {
            if (beanName.equals("userDao1")) {
                bean = Proxy.newProxyInstance(UserDaoImpl2.class.getClassLoader(), new Class[]{UserDao.class}, new MyInvocationHandler2(bean));
            }
        } catch (Exception e) {

        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
